package com.grts.mall.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.grts.mall.common.CommonResult;
import com.grts.mall.pojo.Image;
import com.grts.mall.pojo.Product;
import com.grts.mall.pojo.vo.DetalisResult;
import com.grts.mall.pojo.vo.SerachCondtion;
import com.grts.mall.pojo.vo.SerachResult;
import com.grts.mall.service.ImageService;
import com.grts.mall.service.ProductService;

@Controller
public class ProductListController {
	@Autowired
	private ProductService productService;
	
	@Autowired
	private ImageService imageService;
	
	@RequestMapping("/product/list")
	@ResponseBody
	public CommonResult mallList(SerachCondtion vo) {
		SerachResult serach = this.productService.serach(vo);
		return CommonResult.success(serach);
	}
	
	@RequestMapping("/product/details")
	@ResponseBody 
	public CommonResult details(Long pid) {
		Product product = this.productService.findById(pid);
		List<Image> images = this.imageService.findByImages(pid);
		DetalisResult data = new DetalisResult();
		data.setImages(images);
		data.setPro(product);
		return CommonResult.success(data);
	}
}
